import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/",
    component: () => import("@/layout/index.vue"),
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/home/index.vue"),
        meta: {
          title: "首页",
          icon: "el-icon-message-solid"
        }
      }
    ]
  },
  {
    path: "/product",
    name: "Product",
    component: () => import("@/layout/index.vue"),
    meta: {
      title: "商品管理",
      icon: "el-icon-s-promotion"
    },
    children: [
      {
        path: "tardemark",
        name: "Trademark",
        component: () => import("@/views/product/Trademark/index.vue"),
        meta: {
          title: "品牌管理"
        }
      },
      {
        path: "attr",
        name: "Attr",
        component: () => import("@/views/product/Attr/index.vue"),
        meta: {
          title: "平台属性管理"
        }
      },
      {
        path: "sku",
        name: "Sku",
        component: () => import("@/views/product/Sku/index.vue"),
        meta: {
          title: "Sku管理"
        }
      },
      {
        path: "spu",
        name: "Spu",
        component: () => import("@/views/product/Spu/index.vue"),
        meta: {
          title: "Spu管理"
        }
      }
    ]
  },
  {
    path: "/acl",
    name: "acl",
    component: () => import("@/layout/index.vue"),
    meta: {
      title: "权限管理",
      icon: "el-icon-s-custom"
    },
    children: [
      {
        path: "user",
        name: "User",
        component: () => import("@/views/acl/user/index.vue"),
        meta: {
          title: "用户管理"
        }
      },
      {
        path: "/acl/role/list",
        name: "Role",
        component: () => import("@/views/acl/role/index.vue"),
        meta: {
          title: "角色管理"
        }
      }
    ]
  },
  {
    path: "/404",
    component: () => import("@/views/404"),
    hidden: true
  },
  // 404 page must be placed at the end !!!
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    mode: "history", // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
